/*
 * $Id: ShemChannelMap.java,v 1.1 2009/06/18 19:52:36 afaichun Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.processor.shemjob;
/**
 * SHeM Channel Map.
 *  A SHeM channel map is used to translate from SHeM binary data fields
 *   into ASCII magnet data fields.  This keeps the ASCII magnet data files
 *   consistent with the ASCII magnet data files used by the EDM.
 *  The EDM used only 6 values and they are in a different order than those
 *   coming from SHeM data.  Therefore, to keep consistency in the 
 *   format (started by EDM data) for the tools that are looking at ASCII
 *   magnet data, (namely, PPADS web pages and possibly other tools) SHeM
 *   data needs to be reordered.
 *  The following mapping is used for LCC and HFO magnet monitors:
 *  <pre>
 *   ASCII                                           EDM    LCC/HFO
 *   Field    Usage                                 Field    Field
 *   ------   ------------------                    -----   ------
 *    0       1st Stage Temp                          0        4
 *    1       2nd Stage Temp                          1        5
 *    2       He Pressure                             2        9
 *    3       He Level (EDM,LCC), He Level1 (HFO)     3       11
 *    4       H2O Flow Rate                           4        0
 *    5       Water Temp                              5        1
 *    6       Recondenser Temp (LCC,HFO)             n/a       6
 *    7       Coldhead Temp (LCC,HFO)                n/a       7
 *    8       LCC Press. Control (LCC,HFO)           n/a      15
 *    9       Nitrogen Level (LCC), He Level2 (HFO)  n/a      10
 *   10       He Loss per Week (LCC,HFO)             n/a      16
 *   11       unused                                 n/a    unused
 *   12       unused                                 n/a    unused
 *   13       unused                                 n/a    unused
 *   14       unused                                 n/a    unused
 *   15       unused                                 n/a    unused
 *   16       unused                                 n/a    unused
 *  </pre>
 *
 * @author Daniel S. Horwitz, Compuware Corp.
 *
 * @version AutoSC P5P6
 */
public class ShemChannelMap {
    /**
     * Unused.  Value used to mark an unused channel in a SHeM channel map.
     */
    public static final int UNUSED = -1;

    /**
     * Channel Map.  The indices in the array are the indices of the fields
     *  in the ASCII magnet data format.  The values in the array are the
     *  indices of the corresponding fields in the binary SHeM data.
     */
    private int[] theChannelMap =
        new int[] {
                     4,   //  0: First Stage Temp
                     5,   //  1: Second Stage Temp
                     9,   //  2: Helium Pressure
                    11,   //  3: Helium Level (LCC), Helium Level1 (HFO)
                     0,   //  4: Water Flow Rate
                     1,   //  5: Water Temperature
                     6,   //  6: Recondenser Temperature
                     7,   //  7: Coldhead Temperature
                    15,   //  8: LCC Pressure Control
                    10,   //  9: Nitrogen Level (LCC), Helium Level2 (HFO)
                    16    // 10: Helium Loss per Week
                  };

    /**
     * Construct a SHeM channel map based on the fixed channel mapping
     *  specified for LCC and HFO magnet monitors.
     */
    public ShemChannelMap()
    {
    }

    /**
     * Get the index of the binary data channel corresponding to the
     *  specified ASCII data channel.  This is used to get the proper
     *  field from the binary data for creating the data in ASCII magnet
     *  data format.
     *
     * @param asciiIndex Index of the requested field in the ASCII
     *  magnet data format.  This is expected to be a non-negative number.
     *
     * @return
     *  Index of the requested field in the binary data format.  Returns
     *   UNUSED if the channel mapping is not defined for the specified
     *   channel.
     */
    public int binaryIndexForAsciiIndex( int asciiIndex )
    {
        if ( asciiIndex < theChannelMap.length )
        {
            return theChannelMap[asciiIndex];
        }
        else
        {
            return UNUSED;
        }
    }
}
